//
//  smcJaikuAPI+streams.m
//  juhu
//
//  Created by Christian Martick on 27.07.07.
//  Copyright 2007 Christian Martick. All rights reserved.
//
//	jaiku api - recent posts of all jaiku users - public timeline sort of
//
//	this objects handle the users contacts posts using rss feed
//
//	Copyright (C) 2007 Christian Martick, http://juhu-mac.blogspot.com
//
//	Permission is hereby granted, free of charge, to any person obtaining a copy
//	of this software and associated documentation files (the "Software"), to deal
//	in the Software without restriction, including without limitation the rights
//	to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//	copies of the Software, and to permit persons to whom the Software is
//	furnished to do so, subject to the following conditions:
//
//	The above copyright notice and this permission notice shall be included in
//	all copies or substantial portions of the Software.
//
//	THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//	IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//	FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//	AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//	LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//	OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
//	THE SOFTWARE.

#import "smcJaikuAPI.h"

@implementation smcJaikuAPI (streams)

- (void) _updateWithURLString: (NSString *) urlString
{//NSLog(@"jaiku: _updateWithURLString");
	//which one for info
	NSString *stream;
	if ([urlString isEqualToString: @"http://jaiku.com/feed/rss"])
		stream = kSmcPublic;
	else
		stream = kSmcPrivate;
	
	//set up
	smcAsyncConnection *connection = [[[smcAsyncConnection alloc] init] autorelease];
	[connection setDelegate: self];
	//and go for it
	[connection beginDownloadFromURL: [NSURL URLWithString: urlString] 
		withTimout: 20 
		userAgent: JUHUCLIENT_VERSION
		andInfo: [NSDictionary dictionaryWithObjectsAndKeys: @"feedcatch", @"kind",
			stream, @"stream", NULL]];
}

- (BOOL) beginUpdateForStream: (NSString *) stream;
{
	//only one at a time
	if (_doingUpdate)
		return NO;

	_doingUpdate = YES;
	if ([stream isEqualToString: kSmcPrivate])
		[self _updateWithURLString: [NSString stringWithFormat: @"http://%@.jaiku.com/contacts/feed/rss?user=%@&personal_key=%@", 
			_username, _username, _personalKey]];
	else
		[self _updateWithURLString: @"http://jaiku.com/feed/rss"];

	return YES;
}

- (id) stream: (NSString *) streamSelector
{
	if (([streamSelector isEqualToString: kSmcPrivate]) || ([streamSelector isEqualToString: kSmcPublic]))
		return [_streams objectForKey: streamSelector];
	else
		return nil;
}

@end
